package com.ruoyi.web.api.factory;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.web.api.RemoteWebService;
import com.ruoyi.web.api.domain.TChapterCatagory;
import com.ruoyi.web.api.domain.TChapterCatagoryVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 用户服务降级处理
 * 
 * @author ruoyi
 */
@Component
public class RemoteWebFallbackFactory implements FallbackFactory<RemoteWebService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteWebFallbackFactory.class);

    @Override
    public RemoteWebService create(Throwable throwable)
    {
        log.error("网站服务调用失败:{}", throwable.getMessage());
        return new RemoteWebService()
        {
            @Override
            public R<List<TChapterCatagory>> all() {
                return R.fail("获取文章分类失败:" + throwable.getMessage());
            }

            @Override
            public R<List<TChapterCatagoryVo>> getCategoryAndChapters() {
                return R.fail("获取文章分类以及分类信息失败:" + throwable.getMessage());
            }
        };
    }
}
